﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Web;
using System.Web.Mvc;
using VCC.Model;
using VCC.Lib.Common;
using VCC.Site.ViewModels;
using VCC.Lib.Paging;
namespace VCC.Site.Controllers
{
    public class RealelstateController : Controller
    {
        //
        // GET: /Realelstate/

        public ActionResult Index()
        {
            return View();
        }
        [ChildActionOnly]
        public ActionResult TabGetRealstate()
        {
            return View();
        }
        public ActionResult TabRealGetCategory(int id)
        {
            ChoVietDataContext eDataContext = new ChoVietDataContext();
            TabRealGetCategoryModel model = new TabRealGetCategoryModel();
            model.Categories = eDataContext.Categories.Where(e => e.PubYN == true && e.ParentID == id).OrderBy("Priority", "ASC").ToList();
            return View(model);
        }
        public ActionResult TabReals(int Id)
        {
            ChoVietDataContext eDataContext = new ChoVietDataContext();
            DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,23,59,59);
            TabRealsModel model = new TabRealsModel();
            int Boxsize = !string.IsNullOrEmpty(Request["Boxsize"]) ? int.Parse(Request["Boxsize"].ToString()) : 8;
            if (Id== 2310)
            {
                model.Category = eDataContext.Categories.Where(e => e.ID == 2).FirstOrDefault();
                model.Ads = eDataContext.Ads.Where(e => e.PublishYN == true && e.StartDate <= today && e.Status != byte.Parse(AdStatus.Deleted.GetHashCode().ToString()) &&
                                         (e.CatID == 2 || e.CatID == 3 || e.CatID == 10))
                                         .OrderBy(string.Format("{0} {1}", "SortDate", "DESC"))
                                         .OrderBy(string.Format("{0} {1}", "VIPTypeID", "ASC"))
                                         .ToPagedList(0, Boxsize);
            }
            if (Id == 1213)
            {
                model.Category = eDataContext.Categories.Where(e => e.ID == 12).FirstOrDefault();
                model.Ads = eDataContext.Ads.Where(e => e.PublishYN == true && e.StartDate <= today && e.Status != byte.Parse(AdStatus.Deleted.GetHashCode().ToString()) &&
                                         (e.CatID == 12 || e.CatID == 13))
                                         .OrderBy(string.Format("{0} {1}", "SortDate", "DESC"))
                                         .OrderBy(string.Format("{0} {1}", "VIPTypeID", "ASC"))
                                         .ToPagedList(0, Boxsize);
            }
            if (Id == 14)
            {
                model.Category = eDataContext.Categories.Where(e => e.ID == Id).FirstOrDefault();
                model.Ads = eDataContext.Ads.Where(e => e.PublishYN == true && e.StartDate <= today && e.Status != byte.Parse(AdStatus.Deleted.GetHashCode().ToString()) &&
                                         (e.CatID == 14))
                                        .OrderBy(string.Format("{0} {1}", "SortDate", "DESC"))
                                         .OrderBy(string.Format("{0} {1}", "VIPTypeID", "ASC"))
                                         .ToPagedList(0, Boxsize);
            }
            return View(model);
        }
    }
}
